/**
 * 
 */
package com.zhiteng.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.zhiteng.entity.CourseNode;

import tk.mybatis.mapper.common.Mapper;

/**  
* <p>Title: CourseNodeMapper.java</p>  
* <p>Description: </p>  
* @author dragon  
* @date 2018年11月8日  
* @version 1.0  
*/

/**
 * 具体操作数据库的Mapper接口，需要继承通用Mapper提供的核心接口：Mapper<School>
 * 泛型类型就是实体类的类型
 *
 */
public interface CourseNodeMapper extends Mapper<CourseNode>{
	
	@Select("SELECT DISTINCT course_name FROM tb_course_node WHERE school_name=#{schoolName}")
	List<String> queryCourseNameBySchool(@Param("schoolName")String SchoolName);
	
	@Select("SELECT DISTINCT teacher_name FROM tb_course_node WHERE school_name=#{schoolName} AND course_name=#{courseName} ORDER BY teacher_name")
	List<String> queryTeacherNameBySchoolAndCourse(@Param("schoolName")String schoolName, @Param("courseName")String courseName);
	
	//	查询指定学校的指定教师星期week有几节课
	@Select("SELECT COUNT(*) FROM tb_course_node WHERE school_id=#{schoolId} AND teacher_id=#{teacherId} AND WEEK=#{week}")
	Integer queryTotalCourseByWeek(@Param("schoolId")String schoolId,@Param("teacherId")String teacherId,@Param("week")String week);
	
	//	teacherId对应的教师在星期week，前nodeIndex上不了，返回该教师这天能上几节他的课
	@Select("SELECT COUNT(*) FROM tb_course_node WHERE teacher_id=#{teacherId} AND WEEK=#{week} and course_num>#{nodeIndex}")
	int queryFirstCount(@Param("teacherId")String teacherId,@Param("week")String week,@Param("nodeIndex")int nodeIndex);
	
	//	算出第startNode节课之后（不含）且在endNode节课之前（不含）的属于该教师的课程数
	@Select("SELECT COUNT(*) FROM tb_course_node WHERE teacher_id=#{teacherId} AND WEEK=#{week} and course_num>#{startNode} and course_num<#{endNode}")
	int queryCountBetween(@Param("teacherId")String teacherId,@Param("week")String week,@Param("startNode")int startNode,@Param("endNode")int endNode);

}
